﻿//********************************************************************************//
//创建日期：<创建日期，2016-02-26>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：行业类型信息
//********************************************************************************//
using System;
using System.Web.UI;
using Entity;
using BLL;
using System.Data;
using Web.Class;

namespace Web.Pages.YongShui.JiChuXX
{
    public partial class HangYeLX : BasePage
    {
        #region 属性

        /// <summary>
        /// 当前操作项ID
        /// </summary>
        private int HangYeLXID
        {
            get
            {
                return Convert.ToInt32(ViewState["_HangYeLXID"]);
            }
            set
            {
                ViewState["_HangYeLXID"] = value;
            }
        }

        /// <summary>
        /// 保存结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        #endregion

        #region 变量
        
        /// <summary>
        /// 行业类型对象
        /// </summary>
         YS_JX_HANGYELX _YS_JX_HANGYELX= new YS_JX_HANGYELX();

        /// <summary>
        /// 行业类型BLL
        /// </summary>
         YS_JX_HANGYELXBLL _YS_JX_HANGYELXBLL = new YS_JX_HANGYELXBLL();

        /// <summary>
        /// 操作日志BLL
        /// </summary>
         SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        #endregion
        
        #region 事件

        /// <summary>
         /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            { 
                InitData();                
                //Display();
                LoadData();                
            }
            //每次回发时从内存中取得数据源重新绑定,否则列头无法排序
            this.gvList.DataSource = this.dtSource;
            this.gvList.DataBind();
        }

        /// <summary>
        /// 绑定空表头
        /// </summary>
        protected override void Render(HtmlTextWriter sender)
        {
            DataTable dt = _YS_JX_HANGYELXBLL.SelectYS_JX_HANGYELXesDynamic("1=0", "", null);
            base.Render(sender);
        }

        ///// <summary>
        ///// 添加操作
        ///// </summary>
        //protected void btnAdd_Click(object sender, EventArgs e)
        //{
        //    InitData();
        //    this.Status = GridViewStatus.Add;
        //    Display();
        //}

        ///// <summary>
        ///// 放弃操作
        ///// </summary>
        //protected void btnCancel_Click(object sender, EventArgs e)
        //{
        //    this.Status = GridViewStatus.Init;
        //    Display();
        //}        
        
        ///// <summary>
        ///// 修改操作
        ///// </summary>
        //protected void lnbModify_Command(object sender, CommandEventArgs e)
        //{
        //    this.HangYeLXID = Convert.ToInt32(e.CommandArgument);
        //    this.Status = GridViewStatus.Update;
        //    Display();
        //    SetData();
        //}

        ///// <summary>
        ///// 删除操作
        ///// </summary>
        //protected void lnbDel_Command(object sender, CommandEventArgs e)
        //{
        //        this.HangYeLXID = Convert.ToInt32(e.CommandArgument);
        //        //执行逻辑删除
        //        _YS_JX_HANGYELX = _YS_JX_HANGYELXBLL.SelectYS_JX_HANGYELX(this.HangYeLXID, null);
        //        //确认涉水对象代码是否在使用
        //        if (new YS_YG_YONGHUXXBLL().SelectYS_YG_YONGHUXXesDynamic(string.Format("s_sheshuidxdm='{0}'", _YS_JX_HANGYELX.S_SHESHUIDXFLDM), null).Rows.Count > 0)
        //        {
        //            PageTools.AlertMsg(this,"当前涉水对象代码正在使用,不允许删除！");
        //            return;
        //        }
        //        //设置操作信息
        //        this._YS_JX_HANGYELX.S_CAOZUOR = LoginInfo.CurrentUser.Account;
        //        this._YS_JX_HANGYELX.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
        //        //设置逻辑删除
        //        this._YS_JX_HANGYELX.I_JLZT = -1;
        //        //执行操作
        //        if (_YS_JX_HANGYELXBLL.InsertOrUpdate(_YS_JX_HANGYELX, null))
        //        {
        //            _SYS_LOGBLL.Log<YS_JX_HANGYELX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "行业类型", OperateState.Delete, _YS_JX_HANGYELX, null);
        //            LoadData();
        //            this.Status = GridViewStatus.Init;
        //            Display();
        //            PageTools.AlertMsg(this, "操作成功！");

        //        }
        //}

        ///// <summary>
        ///// grid保存
        ///// </summary>
        //protected void btnSave_Click(object sender, EventArgs e)
        //{
        //    if (ValidateData())
        //    { 
        //        SaveData(); 
        //    }
        //}

        /// <summary>
        /// 保存验证
        /// </summary>
        /// <returns></returns>
        private bool ValidateData()
        {
            if (this.txtSheShuiDXFLDM.Text == "")
            {
                PageTools.AlertMsg(this, "涉水对象分类代码，不能为空！");
                this.txtSheShuiDXFLDM.Focus();
                return false;
            }
            if (!PageTools.ValidateString(this.txtSheShuiDXFLDM.Text, PageTools.eValidateType.数字))
            {
                PageTools.AlertMsg(this,"你输入的涉水对象分类代码格式不正确，请输入数字类型！");
                this.txtSheShuiDXFLDM.Focus();
                return false;
            }
            if (this.txtSheShuiDXFLMC.Text == "")
            {
                PageTools.AlertMsg(this,"涉水对象分类名称不能为空！");
                this.txtSheShuiDXFLMC.Focus();
                return false;
            }
            if (this.txtHangYeLXFLBM.Text == "")
            {
                PageTools.AlertMsg(this,"行业类型编码不能为空！");
                this.txtHangYeLXFLBM.Focus();
                return false;
            }
            if (!PageTools.ValidateString(this.txtHangYeLXFLBM.Text, PageTools.eValidateType.数字))
            {
                PageTools.AlertMsg(this, "你输入的行业类型编码格式不正确，请输入数字类型！");

                this.txtHangYeLXFLBM.Focus();
                return false;
            }
            if (this.txtHangYeLXFLMC.Text == "")
            {
                PageTools.AlertMsg(this, "行业类型名称不能为空！");
                this.txtHangYeLXFLMC.Focus();
                return false;
            }
            return true;
        }

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            CallbackResult cr = new CallbackResult(e.Parameter);
            int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            if (e.Parameter == "info")
            {
                this._YS_JX_HANGYELX = this._YS_JX_HANGYELXBLL.SelectYS_JX_HANGYELX(id);
                cr.IsSuccess = true;
                cr.IsAlertMsg = false;
                cr.AddValue(this._YS_JX_HANGYELX.S_SHESHUIDXFLDM, this._YS_JX_HANGYELX.S_SHESHUIDXFLMC, this._YS_JX_HANGYELX.S_HANGYELEIXBM, this._YS_JX_HANGYELX.S_HANGYELEIXMC);
                e.Result = cr.ToString();
                return;
            }
            else if (e.Parameter == "del")
            {
                this._YS_JX_HANGYELX = _YS_JX_HANGYELXBLL.SelectYS_JX_HANGYELX(id);
                //确认涉水对象代码是否在使用
                if (new YS_YG_YONGHUXXBLL().SelectYS_YG_YONGHUXXesDynamic(string.Format("s_sheshuidxdm='{0}'", _YS_JX_HANGYELX.S_SHESHUIDXFLDM), null).Rows.Count > 0)
                {
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    cr.Msg = "当前涉水对象代码正在使用,不允许删除！";
                    e.Result = cr.ToString();
                    return;
                }
                //设置逻辑删除
                this._YS_JX_HANGYELX.I_JLZT = -1;
                //执行操作
                _SYS_LOGBLL.Log<YS_JX_HANGYELX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "行业类型", OperateState.Delete, _YS_JX_HANGYELX, null);
                if (_YS_JX_HANGYELXBLL.InsertOrUpdate(_YS_JX_HANGYELX, null))
                {
                    
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = true;
                    cr.Msg = "操作成功！";
                    e.Result = cr.ToString();
                    return;

                }
            }
            else if (e.Parameter == "save")
            {
                OperateState operateState;
                
                //添加
                if (id == -1)
                {
                    this._YS_JX_HANGYELX.ID = 0;
                    this._YS_JX_HANGYELX.I_JLZT = 0;
                    operateState = OperateState.Add;
                }
                //修改
                else
                {
                    //修改操作
                    this._YS_JX_HANGYELX = this._YS_JX_HANGYELXBLL.SelectYS_JX_HANGYELX (id);
                    operateState = OperateState.Modify;
                }
                //判断涉水对象代码是否存在
                if (_YS_JX_HANGYELXBLL.SelectYS_JX_HANGYELXesDynamic(string.Format("I_JLZT=0 and S_SHESHUIDXFLDM='{0}' and ID<>'{1}'", this.txtSheShuiDXFLDM.Text, this._YS_JX_HANGYELX.ID), null).Rows.Count > 0)
                {
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    cr.Msg = "您所输入涉水对象分类代码系统中已经存在使用,请修改。";
                    e.Result = cr.ToString();
                    return;
                }
                _YS_JX_HANGYELX.S_SHESHUIDXFLDM = this.txtSheShuiDXFLDM.Text;
                _YS_JX_HANGYELX.S_SHESHUIDXFLMC = this.txtSheShuiDXFLMC.Text;
                _YS_JX_HANGYELX.S_HANGYELEIXBM = this.txtHangYeLXFLBM.Text;
                _YS_JX_HANGYELX.S_HANGYELEIXMC = this.txtHangYeLXFLMC.Text;
                //设置操作信息
                _YS_JX_HANGYELX.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
                _YS_JX_HANGYELX.D_CAOZUOSJ = DateTime.Now;
                _SYS_LOGBLL.Log<YS_JX_HANGYELX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "行业类型", operateState, _YS_JX_HANGYELX, null);
                if (_YS_JX_HANGYELXBLL.InsertOrUpdate(_YS_JX_HANGYELX, null))
                {
                    
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = true;
                    cr.Msg = "保存成功！";
                    cr.SpecialIndetity=_YS_JX_HANGYELX.ID.ToString();
                    e.Result = cr.ToString();
                    return;
                }
            }
        }

        #endregion

        #region 方法

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
          
        }

        /// <summary>
        /// 数据加载
        /// </summary>
        private void LoadData()
        {
            this.dtSource= _YS_JX_HANGYELXBLL.SelectYS_JX_HANGYELXesAll();
            this.gvList.DataSource = this.dtSource;
            this.gvList.DataBind();
        }

        protected void gvList_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e)
        {
            LoadData();
        }

        ///// <summary>
        /////用于控制添加、修改、查看三种状态的显示
        ///// </summary>
        //private void Display()
        //{
        //    switch (this.Status)
        //    {
        //        case GridViewStatus.Init:
        //            btnAdd.Visible = true;
        //            GridViewContentTable.Visible = false;
        //            this.gvList.Enabled = true;
                    
        //            break;
        //        case GridViewStatus.Search:
        //            btnAdd.Visible = true;
        //            GridViewContentTable.Visible = true;
        //            this.gvList.Enabled = true; 
        //            break;
        //        case GridViewStatus.Update:
        //            btnAdd.Visible = false;
        //            GridViewContentTable.Visible = true;
        //            this.gvList.Enabled = false;
        //            this.lblOperateTip.Text = "修改"; 
        //            this.txtSheShuiDXFLDM.Enabled = false;
        //            this.txtSheShuiDXFLMC.Focus();
        //            break;
        //        case GridViewStatus.Add:
        //            btnAdd.Visible = false;
        //            GridViewContentTable.Visible = true;
        //            this.gvList.Enabled = false;
        //            this.lblOperateTip.Text = "添加";
        //            this.txtSheShuiDXFLDM.Enabled = true;
        //            this.txtSheShuiDXFLDM.Focus();
        //            break;
        //    }
        //}

        ///// <summary>
        ///// 保存数据
        ///// </summary>
        //private void SaveData()
        //{
        //    OperateState operateState;
        //    //添加
        //    if (this.Status == GridViewStatus.Add)
        //    {
        //        operateState = OperateState.Add;
        //        _YS_JX_HANGYELX.ID = 0;
        //        _YS_JX_HANGYELX.I_JLZT = 0;
        //    }
        //    //修改
        //    else
        //    {
        //        //修改操作
        //        operateState = OperateState.Modify;
        //        _YS_JX_HANGYELX = _YS_JX_HANGYELXBLL.SelectYS_JX_HANGYELX(this.HangYeLXID, null);
        //    }
        //    //判断涉水对象代码是否存在
        //    if (_YS_JX_HANGYELXBLL.SelectYS_JX_HANGYELXesDynamic(string.Format("I_JLZT=0 and S_SHESHUIDXFLDM='{0}' and ID<>'{1}'", this.txtSheShuiDXFLDM.Text, this._YS_JX_HANGYELX.ID), null).Rows.Count > 0)
        //    {
        //        PageTools.AlertMsg(this, "您所输入涉水对象分类代码系统中已经存在使用,请修改。");
        //        this.txtSheShuiDXFLDM.Focus();
        //        return;
        //    }
        //    _YS_JX_HANGYELX.S_SHESHUIDXFLDM = this.txtSheShuiDXFLDM.Text;
        //    _YS_JX_HANGYELX.S_SHESHUIDXFLMC = this.txtSheShuiDXFLMC.Text;
        //    _YS_JX_HANGYELX.S_HANGYELEIXBM = this.txtHangYeLXFLBM.Text;
        //    _YS_JX_HANGYELX.S_HANGYELEIXMC = this.txtHangYeLXFLMC.Text;
        //    //设置操作信息
        //    _YS_JX_HANGYELX.S_CAOZUOR = LoginInfo.CurrentUser.Account;
        //    _YS_JX_HANGYELX.D_CAOZUOSJ = DateTime.Now;
        //    //执行操作
        //    if (_YS_JX_HANGYELXBLL.InsertOrUpdate(_YS_JX_HANGYELX, null))
        //    {
        //        _SYS_LOGBLL.Log<YS_JX_HANGYELX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "行业类型", operateState, _YS_JX_HANGYELX, null);   
        //        PageTools.AlertMsg(this, "保存成功！");
        //        this.Status = GridViewStatus.Init;
        //        Display();
        //        LoadData();
        //        //定位记录
        //        this.HangYeLXID=Web.Class.PageTools.FocusOpreateRecord(this.dtSource, this.gvList, "S_SHESHUIDXFLDM", _YS_JX_HANGYELX.S_SHESHUIDXFLDM,true);
        //    }
        //    else
        //    {
        //        PageTools.AlertMsg(this,"保存失败！");
        //    }
        //}

        ///// <summary>
        ///// 给输入框赋值
        ///// </summary>
        //private void SetData()
        //{
        //    _YS_JX_HANGYELX = _YS_JX_HANGYELXBLL.SelectYS_JX_HANGYELX(this.HangYeLXID, null);
        //    this.txtHangYeLXFLBM.Text = _YS_JX_HANGYELX.S_HANGYELEIXBM;
        //    this.txtHangYeLXFLMC.Text = _YS_JX_HANGYELX.S_HANGYELEIXMC;
        //    this.txtSheShuiDXFLDM.Value = _YS_JX_HANGYELX.S_SHESHUIDXFLDM;
        //    this.txtSheShuiDXFLMC.Text = _YS_JX_HANGYELX.S_SHESHUIDXFLMC;
        //}

        #endregion        
    }
 
}